package com.barefootcourier.simplecalc;

import android.app.Activity;
import android.os.Bundle;
import android.view.Menu;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;



public class MainActivity extends Activity {
	EditText firstNumber;
	EditText secondNumber;
	EditText result;
	Double first = 0.0;
	Double second = 0.0;
	Double answer = 0.0;
	
	
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        getMenuInflater().inflate(R.menu.activity_main, menu);
        return true;
    }

    public void buttonAddClick(View v){
    	// deal with adding numbers
    	
    	firstNumber = (EditText) this.findViewById(R.id.editFirstNumber);
    	secondNumber = (EditText) this.findViewById(R.id.editNumberTwo);
    	result = (EditText) findViewById(R.id.editResult);
    	try {
    	
    		first = Double.valueOf(firstNumber.getText().toString());
    		
    	} catch (Exception e) {
    		first = 0.0;
    	}
    	
    	try {
    	second = Double.valueOf(secondNumber.getText().toString());
    	} catch (Exception e)
    	{
    		second = 0.0;
    	}
    
    	answer = first + second;
    	result.setText(answer.toString());
    	
    }
    
    public void buttonSubtractClick(View v){
    	// deal with adding numbers
    	
    	firstNumber = (EditText) this.findViewById(R.id.editFirstNumber);
    	secondNumber = (EditText) this.findViewById(R.id.editNumberTwo);
    	result = (EditText) findViewById(R.id.editResult);
    	try {
    	
    		first = Double.valueOf(firstNumber.getText().toString());
    		
    	} catch (Exception e) {
    		first = 0.0;
    	}
    	
    	try {
    	second = Double.valueOf(secondNumber.getText().toString());
    	} catch (Exception e)
    	{
    		second = 0.0;
    	}
    
    	answer = first - second;
    	result.setText(answer.toString());
    	
    }
    
    public void buttonMultiplyClick(View v){
    	// deal with adding numbers
    	
    	firstNumber = (EditText) this.findViewById(R.id.editFirstNumber);
    	secondNumber = (EditText) this.findViewById(R.id.editNumberTwo);
    	result = (EditText) findViewById(R.id.editResult);
    	try {
    	
    		first = Double.valueOf(firstNumber.getText().toString());
    		
    	} catch (Exception e) {
    		first = 0.0;
    	}
    	
    	try {
    	second = Double.valueOf(secondNumber.getText().toString());
    	} catch (Exception e)
    	{
    		second = 0.0;
    	}
    
    	answer = first * second;
    	result.setText(answer.toString());
    	
    }
    
    public void buttonDivideClick(View v){
    	// deal with adding numbers
    	
    	firstNumber = (EditText) this.findViewById(R.id.editFirstNumber);
    	secondNumber = (EditText) this.findViewById(R.id.editNumberTwo);
    	result = (EditText) findViewById(R.id.editResult);
    	try {
    	
    		first = Double.valueOf(firstNumber.getText().toString());
    		
    	} catch (Exception e) {
    		first = 0.0;
    	}
    	
    	try {
    	second = Double.valueOf(secondNumber.getText().toString());
    	} catch (Exception e)
    	{
    		second = 0.0;
    	}
    
    	answer = first / second;
    	result.setText(answer.toString());
    	
    }
    
    public void buttonCLRClick(View v){
    	// deal with adding numbers
    	
    	firstNumber = (EditText) this.findViewById(R.id.editFirstNumber);
    	secondNumber = (EditText) this.findViewById(R.id.editNumberTwo);
    	result = (EditText) findViewById(R.id.editResult);
    	firstNumber.setText((int) 0.0);
    	
    	
    }
    
}
